package com.academic_system.util;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 20155873 张联富
 * @Description $Description$
 * @methodName $methodName$
 * @date $date$ $time$
 * @return $returns$
 */
public class ExemptionTime {
    public static Date getNetworkTime() {
        Date time=null;
        try {
            URL url = new URL("http://www.baidu.com");
            URLConnection conn = url.openConnection();
            conn.connect();
            long dateL = conn.getDate();
            Date date = new Date(dateL);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String str=dateFormat.format(date);
            System.out.println("str="+str);
            time=dateFormat.parse(str);
            System.out.println("time="+time);
            return time;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        catch (ParseException e) {
            e.printStackTrace();
        }

        return time;
    }
}
